package com.fimmlps.reronge.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fimmlps.reronge.entity.EntryUsage;
import com.fimmlps.reronge.mapper.EntryUsageMapper;
import com.fimmlps.reronge.service.IEntryUsageService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class EntryUsageServiceImpl extends ServiceImpl<EntryUsageMapper, EntryUsage> implements IEntryUsageService {
    @Override
    public ArrayList<EntryUsage> getUsagesFromText(ArrayList<String> ts) {
        ArrayList<EntryUsage> usages = new ArrayList<>();
        for(String s:ts){
            getUsageByName(s,usages);
        }
        return usages;
    }

    private void getUsageByName(String name, ArrayList<EntryUsage> triggers){
        QueryWrapper<EntryUsage> likes = new QueryWrapper<>();
        likes.eq("enabled",0);
        likes.like("text",name);
        List<EntryUsage> ets = list(likes);
        triggers.addAll(ets);
    }

    @Override
    public ArrayList<EntryUsage> getEnabledUsagesBySingleId(int singleId) {
        ArrayList<EntryUsage> usages = (ArrayList<EntryUsage>) baseMapper.selectList(new QueryWrapper<EntryUsage>().eq("enabled",0).eq("entry_single_id",singleId));
        return usages;
    }
}

